package eu.robico.simulator.simulatorinterface.actionpanel;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import eu.robico.simulator.simulatorinterface.MainController;
import eu.robico.simulator.simulatorinterface.communication.Protocol.Trigger;

class ActionPanelPopUp extends JPopupMenu 
{
    private JMenuItem 	startSimulationMenuItem, stopSimulationMenuItem, 
    					loadObstaceSimulationMenuItem, loadProgrammedPathSimulationMenuItem;
    private JMenu loadSimulationMenu;
	
    public ActionPanelPopUp(final ActionPanel actionPanel, Point popUpPoint)
    {
        startSimulationMenuItem = new JMenuItem("Start Simulation");
        startSimulationMenuItem.setEnabled(MainController.getInstance().getSimulatorStatusCopy().isConnected());
        startSimulationMenuItem.addActionListener(new ActionListener()
        {
			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				MainController.getInstance().sendTrigger(Trigger.START);
				actionPanel.startSimulation();
			}
        });
        add(startSimulationMenuItem);
        stopSimulationMenuItem = new JMenuItem("Pauze Simulation");
        stopSimulationMenuItem.setEnabled(MainController.getInstance().getSimulatorStatusCopy().isConnected());
        stopSimulationMenuItem.addActionListener(new ActionListener()
        {
			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				MainController.getInstance().sendTrigger(Trigger.PAUZE);
				actionPanel.stopSimulation();
			}
        });
        add(stopSimulationMenuItem);
        
        loadSimulationMenu = new JMenu("Load simulation");
        
        loadObstaceSimulationMenuItem = new JMenuItem("Load obstacle on colorlane simulation");
        loadObstaceSimulationMenuItem.addActionListener(new ActionListener()
        {
			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				MainController.getInstance().sendTrigger(Trigger.RESTART);
				actionPanel.loadObstacleSimulation();
			}
        });
        loadSimulationMenu.add(loadObstaceSimulationMenuItem);
        
        loadProgrammedPathSimulationMenuItem = new JMenuItem("Load programmed path simulation");
        loadProgrammedPathSimulationMenuItem.addActionListener(new ActionListener()
        {
			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				MainController.getInstance().sendTrigger(Trigger.RESTART);
				actionPanel.loadProgrammedPathSimulation();
			}
        });
        loadSimulationMenu.add(loadProgrammedPathSimulationMenuItem);
        
        add(loadSimulationMenu);
    }
}